//
//  BuyerDetailCollectionViewCell.m
//  UGoods
//
//  Created by dllo on 16/1/21.
//  Copyright © 2016年 蓝鸥科技.李贺. All rights reserved.
//

#import "BuyerDetailCollectionViewCell.h"
#import "FindModel.h"
#import <UIImageView+WebCache.h>
#import "ConstantsDefine.h"
@interface BuyerDetailCollectionViewCell ()

@property (nonatomic, retain) UIImageView *backImageView; /**< 背景图片 */
@property (nonatomic, retain) UILabel *backLabel;
@property (nonatomic, retain) UIImageView *coverImageView; /**< 封面图片 */
@property (nonatomic, retain) UILabel *goodsNameLabel; /**< 商品名 */
@property (nonatomic, retain) UILabel *brandNameLabel; /**< 品牌名 */
@property (nonatomic, retain) UIButton *buyButton;
@property (nonatomic, retain) UILabel *priceLabel; /**< 价格 */

@end

@implementation BuyerDetailCollectionViewCell

- (void)dealloc
{
    [_backImageView release];
    [_backLabel release];
    [_coverImageView release];
    [_goodsNameLabel release];
    [_brandNameLabel release];
    [_priceLabel release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.layer.cornerRadius = 5.0f;
        self.layer.masksToBounds = YES;
        
        self.backImageView = [[UIImageView alloc] init];
        _backImageView.image = [UIImage imageNamed:@"iconfont-liubianxing"];
        [self.contentView addSubview:_backImageView];
        [_backImageView release];
        
        self.backLabel = [[UILabel alloc] init];
        _backLabel.textAlignment = NSTextAlignmentCenter;
        _backLabel.text = @"Pick  up  for  ever";
        _backLabel.font = [UIFont fontWithName:@"Zapfino" size:11 * WIDTH];
        [self.contentView addSubview:_backLabel];
        [_backLabel release];
        
        self.coverImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:_coverImageView];
        [_coverImageView release];
        
        self.goodsNameLabel = [[UILabel alloc] init];
        _goodsNameLabel.textAlignment = NSTextAlignmentCenter;
        _goodsNameLabel.font = [UIFont systemFontOfSize:14 * WIDTH];
        [self.contentView addSubview:_goodsNameLabel];
        [_goodsNameLabel release];
        
        self.brandNameLabel = [[UILabel alloc] init];
        _brandNameLabel.textAlignment = NSTextAlignmentCenter;
        _brandNameLabel.font = [UIFont boldSystemFontOfSize:12 * WIDTH];
        [self.contentView addSubview:_brandNameLabel];
        [_brandNameLabel release];
        
        self.recommendTextView = [[UITextView alloc] init];
        _recommendTextView.font = [UIFont systemFontOfSize:13 * WIDTH];
        _recommendTextView.textColor = [UIColor blackColor];
        _recommendTextView.backgroundColor = [UIColor clearColor];
        _recommendTextView.scrollEnabled = YES;
        [self.contentView addSubview:_recommendTextView];
        [_recommendTextView release];
    
        self.buyButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_buyButton setBackgroundImage:[UIImage imageNamed:@"iconfont-biaoqian-2"] forState:UIControlStateNormal];
        [_buyButton setTitle:@"我 要 买" forState:UIControlStateNormal];
        [_buyButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _buyButton.titleLabel.font = [UIFont systemFontOfSize:13 * WIDTH];
        [self.contentView addSubview:_buyButton];
        
        self.priceLabel = [[UILabel alloc] init];
        _priceLabel.textColor = [UIColor blackColor];
        _priceLabel.font = [UIFont systemFontOfSize:15 * WIDTH];
        [self.contentView addSubview:_priceLabel];
        [_priceLabel release];
        
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
    [super applyLayoutAttributes:layoutAttributes];
    _backImageView.frame = CGRectMake(0, 0, 45 * WIDTH, 40 * HEIGHT);
    _backImageView.center = CGPointMake(self.contentView.center.x, 40 * HEIGHT);
    
    _backLabel.frame = CGRectMake(0, 0, 200 * WIDTH, 15 * HEIGHT);
    _backLabel.center = CGPointMake(self.contentView.center.x, 40 * HEIGHT);
    
    _coverImageView.frame = CGRectMake(0, 0, 200 * WIDTH, 200 * HEIGHT);
    _coverImageView.center = CGPointMake(self.contentView.center.x, 180 * HEIGHT);
    
    _goodsNameLabel.frame = CGRectMake(0, 0, 200 * WIDTH, 20 * HEIGHT);
    _goodsNameLabel.center = CGPointMake(self.contentView.center.x, 300 * HEIGHT);
    
    _brandNameLabel.frame = CGRectMake(0, 0, 200 * WIDTH, 15 * HEIGHT);
    _brandNameLabel.center = CGPointMake(self.contentView.center.x, 320 * HEIGHT);
    
    _recommendTextView.frame = CGRectMake(0, 0, 250 * WIDTH, 70 * HEIGHT);
    _recommendTextView.center = CGPointMake(self.contentView.center.x, 340 * HEIGHT);
    
    _buyButton.frame = CGRectMake(0, 400 * HEIGHT, 80 * WIDTH, 20 * HEIGHT);
    
    _priceLabel.frame = CGRectMake(260 * WIDTH, 400 * HEIGHT, 50 * WIDTH, 20 * HEIGHT);
}

- (void)setModel:(FindModel *)model {
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    [_coverImageView sd_setImageWithURL:[NSURL URLWithString:model.cover] placeholderImage:[UIImage imageNamed:@"place3"]];
    _goodsNameLabel.text = model.goods_name;
    _brandNameLabel.text = model.brand_name;
    _priceLabel.text = [NSString stringWithFormat:@"¥ %@", [model.cost_price stringValue]];
    
    
//    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
//    paragraphStyle.lineSpacing = 5;// 字体的行间距
//    NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:13],                                 NSParagraphStyleAttributeName:paragraphStyle,NSForegroundColorAttributeName:[UIColor blackColor]};
//    _recommendTextView.attributedText = [[NSAttributedString alloc] initWithString:model.recommendStr attributes:attributes];
//    _recommendTextView.text = model.recommendStr;
    
    
}


@end
